//  [10/10/2013 OMEGA] created

#include <QAction>
#include <QActionGroup>
#include "DuelAssECommon.h"
#include "DuelAssEWorkbench.h"
#include "DuelAssEActionManager.h"

static QActionGroup* createActionGroup(QObject *parent, bool exclusive = false)
{
	QActionGroup * rc = new QActionGroup(parent);
	rc->setExclusive(exclusive);
	return rc;
}

static QAction* createSeparator(QObject *parent)
{
	QAction * rc = new QAction(parent);
	rc->setSeparator(true);
	return rc;
}

DAssEActionManager::DAssEActionManager( DAssEWorkbench* parent ) :
	QObject(parent),
	mParent(parent),
	mFileActions(createActionGroup(this)),
	mEditActions(createActionGroup(this)),
	mResentFileActions(createActionGroup(this)),
	mProjectActions(createActionGroup(this)),
	mNewProjAct(new QAction(this)),
	mOpenProjAct(new QAction(this)),
	mSaveProjAct(new QAction(this)),
	mCloseProjAct(new QAction(this)),
	mQuitAct(new QAction(this)),
	mEditProjAct(new QAction(this))
{
	mNewProjAct->setShortcut(QKeySequence::New);
	connect(mNewProjAct, SIGNAL(triggered()), mParent, SLOT(createNewProject()));
	mFileActions->addAction(mNewProjAct);

	mOpenProjAct->setShortcut(QKeySequence::Open);
	connect(mOpenProjAct, SIGNAL(triggered()), mParent, SLOT(openProject()));
	mFileActions->addAction(mOpenProjAct);

	mFileActions->addAction(createRecentProjectMenu());
	mFileActions->addAction(createSeparator(this));

	mSaveProjAct->setShortcut(QKeySequence::Save);
	connect(mSaveProjAct, SIGNAL(triggered()), mParent, SLOT(saveProject()));
	mFileActions->addAction(mSaveProjAct);

	mFileActions->addAction(createSeparator(this));

	connect(mCloseProjAct, SIGNAL(triggered()), mParent, SLOT(closeProject()));
	mFileActions->addAction(mCloseProjAct);

	mFileActions->addAction(createSeparator(this));
	connect(mQuitAct, SIGNAL(triggered()), mParent, SLOT(quit()));
	mFileActions->addAction(mQuitAct);

	connect(mEditProjAct, SIGNAL(triggered()), mParent, SLOT(editProjectProperties()));
	mProjectActions->addAction(mEditProjAct);
}

DAssEActionManager::~DAssEActionManager()
{

}

QAction* DAssEActionManager::createRecentProjectMenu()
{
	QMenu *menu = new QMenu;
	QAction *act;
	// Need to insert this into the QAction.
// 	for (int i = 0; i < MaxRecentFiles; ++i) {
// 		act = new QAction(this);
// 		act->setVisible(false);
// 		connect(act, SIGNAL(triggered()), this, SLOT(openRecentForm()));
// 		m_recentFilesActions->addAction(act);
// 		menu->addAction(act);
// 	}
// 	updateRecentFileActions();
// 	menu->addSeparator();
// 	act = new QAction(QIcon::fromTheme("edit-clear"), tr("Clear &Menu"), this);
// 	act->setObjectName(QLatin1String("__qt_action_clear_menu_"));
// 	connect(act, SIGNAL(triggered()), this, SLOT(clearRecentFiles()));
// 	m_recentFilesActions->addAction(act);
// 	menu->addAction(act);
// 
 	act = new QAction(this);
 	act->setMenu(menu);
	return act;
}
